# -*- coding: utf-8 -*-
"""
-------------------------------------------------
   File Name：      Car
   Description :
   Author :         samge
   date：            17-11-7
-------------------------------------------------
   Change Activity: 17-11-7:
-------------------------------------------------
"""
__author__ = 'samge'
import random
class Car:
    def __init__(self):
        self.speed=0
        self.miles=0
        self.time=0
    def upSpeed(self):
        self.speed+=random.randint(1,100)
        self.miles+=random.randint(1,100)
        self.time+=random.randint(1,3)
    def downSpeed(self):
        self.speed-=random.randint(1,50)
        self.miles+=random.randint(1,20)
        self.time+=random.randint(1,9,3)
    def broken(self):
        self.speed=0
    def sayState(self):
        print("当前状态为：\n速度={}".format(self.speed)+"\n里程={}".format(self.miles)+"\n时间={}".format(self.time))
    def averageSpeed(self):
        if self.time != 0:
            print("平均速度为：{}".format(self.miles/self.time))

if __name__=="__main__":
    car = Car()
    print("create a new car,start run~")
    while True:
        action=input("怎么操作？[A]-加速，[D]-减速，[B]-停车，[V]-平均速度").upper()
        if action not in "ADBV" or len(action) != 1:
            print("你的操作太超前，我无法识别")
            continue
        if action == "A":
            car.upSpeed()
        elif action == "D":
            car.downSpeed()
        elif action == "B":
            car.broken()
        elif action == "V":
            car.averageSpeed()
        car.sayState()
